var productIntroduce = {
  swiper: function() {
    //轮播插件
    //  var this=that;
    var mySwiper = new Swiper('.swiper-container', {
      autoplay: 3000, //可选选项，自动滑动
      //height: 150,
      //width:' 100%',
      pagination: '.swiper-pagination',
      paginationElement: 'span',
      autoplayDisableOnInteraction: false,
      callback: function() {}
    })
  },
  scrollToElement: function(ele, speed) {
    if(!speed) speed = 300;
    if(!ele) {
      $("html,body").animate({
        scrollTop: 0
      }, speed);
    } else {
      if(ele.length > 0) $("html,body").animate({
        scrollTop: $(ele).offset().top - $("#barBox").height()
      }, speed);
    }
    return false;
  },
  isHidden: function(ele, btnEle, className, distance) {
    //是否隐藏
    if(ele.height() > distance) {
      ele.addClass(className)
      btnEle.removeClass("hidden")
    }
  },
  loadMore: function(btnEle, ele, className) {
    //查看更多
    btnEle.on("click", function() {
      ele.toggleClass(className)
      if(ele.hasClass(className)) {
        btnEle.html("显示更多")
        $("html,body").animate({
          scrollTop: $(ele).offset().top - $("#barBox").height()
        }, 300);
      } else {
        btnEle.html("立即收起")
      }
    })
  },
  getInfo: function() {
    //获得数据
    var that = this;
    var param = {
      templateId: common.getUrlParams("templateId")
    }
    console.log(param)
    common.get({
      url: "/productDetails.shtml",
      data: param,
      callback: function(data) {
        console.log(data)
        var bannerData = ['http://7xq0ch.com1.z0.glb.clouddn.com/ztc/1512108006581/VGyuo0RI.jpg?e=1512111606&token=TwDqISTq2s5np1-uIOvgFKkUw-ZdCiJX6zd6ftIN:UIC9305Sz7KZnNufBx5LLb0mrCE=',
            'http://7xq0ch.com1.z0.glb.clouddn.com/ztc/1512108006598/GQd7zaQe.jpg?e=1512111606&token=TwDqISTq2s5np1-uIOvgFKkUw-ZdCiJX6zd6ftIN:TV3f0VFjN_BuMX0cGw_L_uSm7L0=',
            'http://7xq0ch.com1.z0.glb.clouddn.com/ztc/1512108006589/4VwQuIII.jpg?e=1512111606&token=TwDqISTq2s5np1-uIOvgFKkUw-ZdCiJX6zd6ftIN:Gzj6UgFOCrG5gFMm5jXfmReHZC4=',
            'http://7xq0ch.com1.z0.glb.clouddn.com/ztc/1512108006590/5A5vBmFx.png?e=1512111606&token=TwDqISTq2s5np1-uIOvgFKkUw-ZdCiJX6zd6ftIN:6UVNNow1w3hkU6bQjBEJNsh8SvE='
          ]
          $("#bannerSrc").tmpl(bannerData).appendTo('#banners');
        that.swiper();
      }
    });
  },
  init: function() {
    //初始化
    var that = this;
    this.isHidden($("#scheduling"), $("#showScheduling"), "scheduling-conceal", 300)
    this.isHidden($("#features"), $("#showFeatures"), "features-conceal", 300)
    this.isHidden($("#ticketInfo"), $("#showNotice"), "ticket-info-conceal", 300)
    this.loadMore($("#showNotice"), $("#ticketInfo"), "ticket-info-conceal")
    this.loadMore($("#showScheduling"), $("#scheduling"), "scheduling-conceal")
    this.loadMore($("#showFeatures"), $("#features"), "features-conceal")
    $(window).scroll(function() {
      //滚动条事件
      if($("#barBox").offset().top - $("#containerBox").scrollTop() < 0) {
        $("#barBox").addClass("position-bar")
      }
      if($("#scheduling").offset().top - $("#containerBox").scrollTop() > 0) {
        $("#barBox").removeClass("position-bar");
        $(".bar-item").removeClass("active")
        $("#routing").addClass("active");
      }
      if(($("#ticketInfo").offset().top - $("#barBox").height()) - $("#containerBox").scrollTop() < 10) {
        $(".bar-item").removeClass("active")
        $("#buyTicketInfo").addClass("active");
      }
      if($(this).scrollTop() + $(this).height() == $(document).height()) {
        $(".bar-item").removeClass("active")
        $("#buyTicketInfo").addClass("active");
      }
    })
    $(".bar-item").on("click", function() {
      //tab切换
      that.scrollToElement('#' + $(this).attr("anchor"), 300)
      $(".bar-item").removeClass("active");
      $(this).addClass("active");
    })
  },
}
productIntroduce.init();
productIntroduce.getInfo();